﻿// -----------------------------------------------------------------------
// <copyright file="PositionAdditionProvider.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Proto
{
    using System.Linq;
    using System.Text;

    using Proto.Fields;
    using Proto.Providers;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class PositionAdditionProvider 
    {
        private readonly PositionDataSource m_PositionDataSource;
        
        public PositionAdditionProvider( PositionDataSource source )
        {
            m_PositionDataSource = source;
        }

        public Sub<Position> Request( BookCode book )
        {
            Sub<Position> sub = new Sub<Position>( new QuickKey( FieldID.BookCode, book ),
                RunnerRegistry.APP );

            RunnerRegistry.INTEGRATION.Enqueue( 
                delegate
                    {
                        NotifyList<Position> list = m_PositionDataSource.GetPositions( book );
                        sub.EnqueueBatchAddition(list);
                    } );

            return sub;
        }
    }
}
